namespace jsWrite {
    class Notifier {
        private observes:Observe[] = [];
        constructor(){

        }
        add(obs:Observe){
            this.observes.push(obs);
        }
        remove(obs:Observe){
            this.observes = this.observes.filter(item=>obs!==item);
        }
        notify(){
            let len = this.observes.length;
            for (let index = 0; index < len; index++) {
                this.observes[index].update();
            }
        }
    }
    class Observe {
        private text:string;
        constructor(text:string){
            this.text = text;
        }
        update() {
            console.log(this.text);
        }
    }
    let notifier = new Notifier();
    let obs1 = new Observe('我是观察者1');
    let obs2 = new Observe('我是观察者2');
    notifier.add(obs1);
    notifier.add(obs2);
    notifier.notify()
}